package com.ls.herostory.cmdhandler;

import com.ls.herostory.msg.GameMsgProtocol;
import com.ls.herostory.rank.RankRedisManager;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author liangsu
 * @version v1.0
 * @Description 查询rank排行榜
 * @Date 2020/10/14 14:05
 * @since
 */
public class GetRankCmdHandler implements CmdHandler<GameMsgProtocol.GetRankCmd> {

    @Override
    public void handleCmd(ChannelHandlerContext ctx, GameMsgProtocol.GetRankCmd cmd) {

        RankRedisManager.getIntance().asyncGetRanks((rankItems) ->{
            GameMsgProtocol.GetRankResult.Builder builder = GameMsgProtocol.GetRankResult.newBuilder();
            for (GameMsgProtocol.GetRankResult.RankItem rankItem : rankItems) {
                builder.addRankItem(rankItem);
            }
            ctx.writeAndFlush(builder.build());
        });

    }

}
